<script>
// If the function is invoked using Function.call() or Function.apply(), 
// this will be set to the first argument passed to .call()/.apply(). 
// If the first argument passed to .call()/.apply() is null or undefined, 
// this will refer to the global object (which is the window object in web browsers).


// A function invoked using Function.call()
var myObject = {
	sayHello: function() {
		console.log( "Hi! My name is " + this.myName );
	},
	myName: "Rebecca"
};

var secondObject = {
	myName: "Colin"
};

myObject.sayHello(); // "Hi! My name is Rebecca"
myObject.sayHello.call( secondObject ); // "Hi! My name is Colin"


//A function created using Function.bind()
var myName = "the global object";
var sayHello = function() {
	console.log( "Hi! My name is " + this.myName );
};
var myObject = {
	myName: "Rebecca"
};
var myObjectHello = sayHello.bind( myObject );
sayHello(); // "Hi! My name is the global object"
myObjectHello(); // "Hi! My name is Rebecca"


//A function being attached to an object at runtime.
var myName = "the global object";
var sayHello = function() {
	console.log( "Hi! My name is " + this.myName );
};
var myObject = {
	myName: "Rebecca"
};
var secondObject = {
	myName: "Colin"
};
myObject.sayHello = sayHello;
secondObject.sayHello = sayHello;
sayHello(); // "Hi! My name is the global object"
myObject.sayHello(); // "Hi! My name is Rebecca"
secondObject.sayHello(); // "Hi! My name is Colin"


var myNamespace = {
		myObject: {
			sayHello: function() {
				console.log( "Hi! My name is " + this.myName );
			},
			myName: "Rebecca"
		}
};
var obj = myNamespace.myObject;
obj.sayHello(); // "Hi! My name is Rebecca"
</script>